//验证码
let btn = document.querySelector('#btn');
let yz = document.querySelector('#yz')
let yz_ipt = document.querySelector('.vfc')
let yz_tip = yz.parentNode.children[1]
yz.innerText = YZM()
btn.onclick = function () {
    yz.innerText = YZM()
}
let Yzm = yz_ipt.oninput = function () {
    if (yz_ipt.value.trim().toLowerCase() == yz.innerText.toLowerCase()) {
        yz_tip.innerText = 'YES'
        yz_tip.style.color = 'green'
        return true
    } else {
        yz_tip.innerText = 'NO'
        yz_tip.style.color = 'red'
        return false
    }
}



// 鼠標移入登錄和註冊頁面span跟著移動
$('.a').mouseenter(function () {
    $('ul span:last-child')
        .stop()
        .animate({
            left: 90 * $(this).index()
        })
})
//鼠标移入img 提示显示
let img = document.querySelector('.img')
let img_tip = img.parentNode.children[1]
let code = document.querySelector('.code')
img.onmouseenter = function () {
    img_tip.style.display = 'block'
}
img.onmouseleave = function () {
    img_tip.style.display = 'none'
}
$('.img').on('click', function () {
    code.style.display = 'flex'
})
let img1 = document.querySelectorAll('.img')[1]
let img1_tip = img1.parentNode.children[5]
img1.onmouseenter = function () {
    img1_tip.style.display = 'block'
}
img1.onmouseleave = function () {
    img1_tip.style.display = 'none'
}
$('.img1').on('click', function () {
    code.style.display = 'none'
})
// 封裝函數判斷是否正確
function AGE(a, r, t) {
    var n = a.val().trim();//去除前后的空格
    var r
    if (r.test(n)) {
        t.text('YES')
        t.removeClass('wrong')
        t.addClass('right_light')
        return true
    }
    else {
        t.text('NO')
        t.addClass('wrong')
        return false
    }
}
let res1 = function () {
    return AGE($('.ipt_One'), /^[a-zA-Z0-9\u4E00-\u9FA5]{2,6}$/, $('.tip'))
}
let res2 = function () {
    return AGE($('.ipt_Psd'), /^1[34578]\d{9}$/, $('.pwd_tip'))
}
let btn1 = document.querySelector('.btn')
var flag = null
btn1.onclick = () => {
    flag = btn1.checked
    if (flag == true) {
        btn_tip.innerHTML = 'YES'
        btn_tip.className = 'right_light'
    } else {
        btn_tip.innerHTML = 'NO'
        btn_tip.className = 'wrong'
    }
}
let btn_tip = btn1.parentNode.children[1]
$('.ipt_One').on('input', res1)
$('.ipt_Psd').on('input', res2)
$('.sub').on('submit', function (e) {
    if (!(res1() && res2() && Yzm()&&flag)) {
        btn_tip.innerHTML = 'NO'
        btn_tip.className = 'wrong'
        e = e || window.event;
        e.preventDefault ? e.preventDefault() : e.returnValue = false;
    }
})
